package ca.uwindsor.cs.deepweb.estimation.method.border;

import java.io.IOException;
import java.util.ArrayList;

import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation;

import ca.uwindsor.cs.deepweb.estimation.RandomWordSelector;

public class Experiment {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// args[0] index directory
		// args[1] querypool file
		// args[2] number of random queries needed
		// args[3] number of trials

		if (args.length != 4) {
			System.exit(-1);
		}
		RandomWordSelector selector = new RandomWordSelector(
				args[1], "UTF-8");
		ArrayList<String> querypool = selector.getWordList();
		int wordsquantity = Integer.parseInt(args[2]);
		ArrayList<String> words = new ArrayList<String>(wordsquantity);

		int times = Integer.parseInt(args[3]);
		int meanvalue = 0;
		StandardDeviation sd = new StandardDeviation();
		double[] e_sizes = new double[times];
		int d;
		int meansampledsize = 0;
		try {
			for (int i = 0; i < times; i++) {
				words.clear();
				for (int j = 0; j < wordsquantity; j++) {
					words.add(selector.getRandomWord());
				}
				QueryRunner runner = new QueryRunner(args[0], querypool, words);
				d = runner.esitmate();
				e_sizes[i] = (double) d;
				meanvalue += d/times;
				meansampledsize += runner.getUniqueDocumentIDs().size();
			}
			//meanvalue = meanvalue / times;
			meansampledsize = meansampledsize / times;
			System.out.println(meansampledsize);
			System.out.println(meanvalue);
			System.out.println(sd.evaluate(e_sizes));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
